package cn.stylefeng.guns.modular.testpicture.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.TestPicture;
import cn.stylefeng.guns.modular.testpicture.service.ITestPictureService;

/**
 * 图片上传测试控制器
 *
 * @author fengshuonan
 * @Date 2018-12-13 15:18:23
 */
@Controller
@RequestMapping("/testPicture")
public class TestPictureController extends BaseController {

    private String PREFIX = "/testpicture/testPicture/";

    @Autowired
    private ITestPictureService testPictureService;

    /**
     * 跳转到图片上传测试首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "testPicture.html";
    }

    /**
     * 跳转到添加图片上传测试
     */
    @RequestMapping("/testPicture_add")
    public String testPictureAdd() {
        return PREFIX + "testPicture_add.html";
    }

    /**
     * 跳转到修改图片上传测试
     */
    @RequestMapping("/testPicture_update/{testPictureId}")
    public String testPictureUpdate(@PathVariable Integer testPictureId, Model model) {
        TestPicture testPicture = testPictureService.selectById(testPictureId);
        model.addAttribute("item",testPicture);
        LogObjectHolder.me().set(testPicture);
        return PREFIX + "testPicture_edit.html";
    }

    /**
     * 获取图片上传测试列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return testPictureService.selectList(null);
    }

    /**
     * 新增图片上传测试
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TestPicture testPicture) {
        testPictureService.insert(testPicture);
        return SUCCESS_TIP;
    }

    /**
     * 删除图片上传测试
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer testPictureId) {
        testPictureService.deleteById(testPictureId);
        return SUCCESS_TIP;
    }

    /**
     * 修改图片上传测试
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TestPicture testPicture) {
        testPictureService.updateById(testPicture);
        return SUCCESS_TIP;
    }

    /**
     * 图片上传测试详情
     */
    @RequestMapping(value = "/detail/{testPictureId}")
    @ResponseBody
    public Object detail(@PathVariable("testPictureId") Integer testPictureId) {
        return testPictureService.selectById(testPictureId);
    }
}
